#include "LCommon.h"

initSing(CLog);

void TimeString()
{
	time_t t;
	time(&t);
	tm* tM = localtime(&t);
	printf("%02u:%02u ", tM->tm_hour, tM->tm_min);
}

void CLog::Notice(const char* tit, const char* message, ...)
{
	lock.Acquire();
	HANDLE stds = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(stds, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	TimeString();
	printf("N %s: ", tit);
	va_list ap;
	va_start(ap, message);
	SetConsoleTextAttribute(stds, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
	vprintf(message, ap);
	va_end(ap);
	printf("\n");
	lock.Release();
}

void CLog::Error(const char* tit, const char* message, ...)
{
	lock.Acquire();
	HANDLE stds = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(stds, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	TimeString();
	printf("N %s: ", tit);
	va_list ap;
	va_start(ap, message);
	SetConsoleTextAttribute(stds, FOREGROUND_RED | FOREGROUND_INTENSITY);
	vprintf(message, ap);
	va_end(ap);
	SetConsoleTextAttribute(stds, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
	printf("\n");
	lock.Release();
}

void CLog::Success(const char* tit, const char* message, ...)
{
	lock.Acquire();
	HANDLE stds = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(stds, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	TimeString();
	printf("N %s: ", tit);
	va_list ap;
	va_start(ap, message);
	SetConsoleTextAttribute(stds, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
	vprintf(message, ap);
	va_end(ap);
	SetConsoleTextAttribute(stds, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
	printf("\n");
	lock.Release();
}